package com.kgc.storeconsumer.controller;

import com.kgc.basic.util.ResponseMsg;
import com.kgc.store.pojo.InventoryProfit;
import com.kgc.store.pojo.OutStore;
import com.kgc.storeconsumer.feign.InventoryProfitFeign;
import com.kgc.storeconsumer.feign.InventoryProfitWorkFlowFeign;
import com.kgc.storeconsumer.feign.OutStoreFeign;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Controller
@CrossOrigin("*")
@RequestMapping("/inventoryProfit")
public class InventoryProfitController {
    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private InventoryProfitFeign inventoryProfitFeign;

    @Autowired
    private InventoryProfitWorkFlowFeign inventoryProfitWorkFlowFeign;

    @RequestMapping("getInventoryProfitList")
    @ResponseBody
    public ResponseMsg getInventoryProfitList(@RequestBody Map<String, Object> map){
        logger.info("InventoryProfitController getInventoryProfitList map:"+map);
        ResponseMsg msg =inventoryProfitFeign.getInventoryProfitList(map);
        logger.debug("InventoryProfitController getInventoryProfitList msg:"+msg);
        return msg;
    }

    @RequestMapping("delInventoryProfit")
    @ResponseBody
    public ResponseMsg delInventoryProfit(String code){
        logger.info("InventoryProfitController delInventoryProfit code:"+code);
        ResponseMsg msg =inventoryProfitFeign.delInventoryProfit(code);
        logger.debug("InventoryProfitController delInventoryProfit msg:"+msg);
        return msg;
    }

    @RequestMapping("insertInventoryProfit")
    @ResponseBody
    ResponseMsg insertInventoryProfit(@RequestBody InventoryProfit inventoryProfit){
        logger.info("InventoryProfitController insertInventoryProfit inventoryProfit:"+inventoryProfit);
        ResponseMsg msg =inventoryProfitFeign.insertInventoryProfit(inventoryProfit);
        logger.debug("InventoryProfitController insertInventoryProfit msg:"+msg);
        return msg;
    }

    @RequestMapping("check")
    @ResponseBody
    ResponseMsg check(@RequestBody Map<String,Object> map){
        ResponseMsg responseMsg = new ResponseMsg();
        logger.info("SalesOrdersController check params,{}",map.toString());
        Map<String,Object> variables = new HashMap<>();
        variables.put("code",(String) map.get("code"));//单据编号
        variables.put("checkManId",(Integer) map.get("checkManId"));//审批人
        variables.put("checkManName",(String) map.get("checkManName"));//审批人
        variables.put("checkComment",(String) map.get("checkComment"));//审批意见
        variables.put("checkDate",new Date());//审批时间
        variables.put("checkRes",(boolean)map.get("checkRes"));//审批结果
        com.kgc.activiti.util.ResponseMsg msg=  inventoryProfitWorkFlowFeign.competeTask(variables);
        responseMsg.setCode(msg.getCode());
        responseMsg.setMsg(msg.getMsg());
        return responseMsg;
    }
}
